﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Undsf.RmmvDbms.Attribute;
using Undsf.RmmvDbms.Data.Internal;

namespace Undsf.RmmvDbms.Data
{
    [Entity(Name = "职业")]
    class Class
    {
        [EntityField(Index = 0, Name = "编号", BasicType = EntityField.BasicTypeInteger)]
        public int id { get; set; }

        [EntityField(Index = 1, Name = "经验曲线", BasicType = EntityField.BasicTypeInteger)]
        public List<int> expParams { get; set; }

        [EntityField(Index = 2, Name = "特性", BasicType = EntityField.BasicTypeList, ObjectType = EntityField.ObjectTypeTrait)]
        public List<Trait> traits { get; set; }

        [EntityField(Index = 3, Name = "习得技能", BasicType = EntityField.BasicTypeList)]
        public List<LearnSkill> learnings { get; set; }

        [EntityField(Index = 4, Name = "名称", BasicType = EntityField.BasicTypeString)]
        public string name { get; set; }

        [EntityField(Index = 5, Name = "备注", BasicType = EntityField.BasicTypeString)]
        public string note { get; set; }

        [JsonProperty(PropertyName = "params")]
        public List<List<int>> _params { get; set;}

        [EntityField(Index = 6, Name = "属性成长 - 生命值", BasicType = EntityField.BasicTypeList, ObjectType = EntityField.BasicTypeInteger)]
        [JsonIgnore]
        public List<int> Health { get; set; }

        [EntityField(Index = 7, Name = "属性成长 - 法力值", BasicType = EntityField.BasicTypeList, ObjectType = EntityField.BasicTypeInteger)]
        [JsonIgnore]
        public List<int> Mana { get; set; }

        [EntityField(Index = 8, Name = "属性成长 - 物理攻击", BasicType = EntityField.BasicTypeList, ObjectType = EntityField.BasicTypeInteger)]
        [JsonIgnore]
        public List<int> PhysicsAtk { get; set; }

        [EntityField(Index = 9, Name = "属性成长 - 物理防御", BasicType = EntityField.BasicTypeList, ObjectType = EntityField.BasicTypeInteger)]
        [JsonIgnore]
        public List<int> PhysicsDef { get; set; }

        [EntityField(Index = 10, Name = "属性成长 - 魔法攻击", BasicType = EntityField.BasicTypeList, ObjectType = EntityField.BasicTypeInteger)]
        [JsonIgnore]
        public List<int> MagicalAtk { get; set; }

        [EntityField(Index = 11, Name = "属性成长 - 魔法防御", BasicType = EntityField.BasicTypeList, ObjectType = EntityField.BasicTypeInteger)]
        [JsonIgnore]
        public List<int> MagicalDef { get; set; }

        [EntityField(Index = 12, Name = "属性成长 - 敏捷", BasicType = EntityField.BasicTypeList, ObjectType = EntityField.BasicTypeInteger)]
        [JsonIgnore]
        public List<int> Agility { get; set; }

        [EntityField(Index = 13, Name = "属性成长 - 幸运", BasicType = EntityField.BasicTypeList, ObjectType = EntityField.BasicTypeInteger)]
        [JsonIgnore]
        public List<int> Luck { get; set; }

        public bool Parse()
        {
            if (_params == null || _params.Count != 8) return false;

            Health = _params[0];
            Mana = _params[1];
            PhysicsAtk = _params[2];
            PhysicsDef = _params[3];
            MagicalAtk = _params[4];
            MagicalDef = _params[5];
            Agility = _params[6];
            Luck = _params[7];

            return true;
        }

        public bool Build()
        {
            _params = new List<List<int>>
            {
                Health, Mana, PhysicsAtk, PhysicsDef, MagicalAtk, MagicalDef, Agility, Luck
            };
            return true;
        }

        public override string ToString()
        {
            return string.Format("{0:D4}  {1}", id, name);
        }
    }
}
